<?php
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

class DocarioControllerFile extends JController {
    function __construct() {
        parent::__construct();
        
        if (JRequest::getCmd('view') == '') {
            JRequest::setVar('view', 'default');
        }
        $this->item_type = 'Default';
        $this->registerTask('addfile', 'editfile');
    }
    
    function newFile() {
        JRequest::setVar('hidemainmenu', true);
        
        $view =& $this->getView('newfile', 'html');
        
        $model = $this->getModel('file');
        $view->setModel($model, true);
        
        $view->display();
    }
    
    function uploadFile() {
        $file = JRequest::getVar('file_upload', null, 'files', 'array');
        $file_name = '';
        $view =& $this->getView('editfile', 'html');
        $model = $this->getModel('file');
        if ($model->newFile($file, $file_name)) {
            $view->setMode(DocarioViewEditfile::EDIT_FILE);
            $view->setMsg(JText::_('A_NEW_REVISION_HAS_BEEN_ADDED'));
        }
        
        $view->setFile($file_name);
        $view->setModel($model, true);
        
        $view->display();
    }
    
    function saveFile() {
        $model = $this->getModel('file');
        if ($model->save()) {
            $msg = JText::_('FILE_SAVED');
        } else $msg = JText::_('FILE_SAVE_FAILED');
        $link = JRoute::_('index.php?option=com_docario&task=files');
        $this->setRedirect($link, $msg);
    }
    
    function editfile() {
        $model = $this->getModel('file');
        $view =& $this->getView('editfile', 'html');
        $model->setId(JRequest::getVar('id'));
        
        $view->setModel($model, true);
        $view->setMode(DocarioViewEditfile::EDIT_FILE);
        $view->display();
    }
    
    function deleteFile() {
    }
    
    function searchusers() {
        $model = $this->getModel('file');
        $view =& $this->getView('fileusers', 'raw');
        $view->setModel($model, true);
        $view->display();
    }
}
?>
